package com.cicadamob.contact.api.service;

import java.util.ArrayList;

import android.content.Context;
import android.os.Handler;

/**加载同事通讯录数据
 * @author lvbo
 *
 */
public class LoadContactDataRunnable implements Runnable {

	private Handler mHandler;
	private int treeid;
	private String treeTable;
	private String personalTable;
	private int what;
	private Context mContext;
	private boolean OnlyNeedInstalled=false;
//	public LoadContactDataRunnable(Context mContext,Handler mHandler,int treeid,String treeTable,String personalTable,int what){
//		this.mHandler=mHandler;
//		this.treeid=treeid;
//		this.treeTable=treeTable;
//		this.personalTable=personalTable;
//		this.what=what;
//		this.mContext=mContext;
//	}
	
	public LoadContactDataRunnable(Context mContext,Handler mHandler,int treeid,String treeTable,String personalTable,int what,boolean OnlyNeedInstalled){
		this.mHandler=mHandler;
		this.treeid=treeid;
		this.treeTable=treeTable;
		this.personalTable=personalTable;
		this.what=what;
		this.mContext=mContext;
		this.OnlyNeedInstalled=OnlyNeedInstalled;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
		ArrayList<Object> childLevelData = new ArrayList<Object>();
		ArrayList<Org> childTreeList = ContactDbHelper.getInstance().queryAllTree(treeid,treeTable);
			
		ArrayList<Contact>	childDepartmentPersonalList = ContactDbHelper.getInstance().queryAll(treeid,personalTable,ContactDbHelper.COMPANY_PERSON_COLUMNS,OnlyNeedInstalled);
		
		if(childDepartmentPersonalList!=null && childDepartmentPersonalList.size()>0)
			childLevelData.addAll(childDepartmentPersonalList);
		if(childTreeList!=null && childTreeList.size()>0)
			childLevelData.add(childTreeList);
		if(mHandler!=null)
			mHandler.obtainMessage(what, childLevelData).sendToTarget();
	}

}
